package com.example.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.system.domain.BusSystemReceivemsg;
import com.example.system.domain.BusSystemReceivemsgRecord;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;


import java.util.List;

/**
* @author CETC
* @description 针对表【bus_system_receivemsg_record_1】的数据库操作Mapper
* @createDate 2025-10-25 18:08:50
* @Entity com.example.system.domain.BusSystemReceivemsgRecord1
*/
public interface BusSystemReceivemsgRecordMapper extends BaseMapper<BusSystemReceivemsgRecord> {

    /**
     * 查询发件记录
     * @param tableName 表名
     * @param fromUid   来自用户
     * @return
     */
    @Select("SELECT * FROM ${tableName} WHERE from_uid = #{fromUid} and is_deleted='0' order by create_time desc")
    public List<BusSystemReceivemsgRecord> selectByBusTableName(@Param("tableName") String tableName, @Param("fromUid")String fromUid);

    /**
     * 获取发送给某人的记录
     * @param tableName
     * @param fromUid
     * @return
     */
    @Select("SELECT * FROM ${tableName} WHERE from_uid = #{fromUid} and to_uid=#{toUid} and is_deleted='0' order by create_time desc")
    public List<BusSystemReceivemsgRecord> selectByBusTableNameAndToUid(@Param("tableName") String tableName, @Param("fromUid")String fromUid,@Param("toUid")String toUid);

    /**
     * 查询发件记录分页
     * @param tableName  表名
     * @param fromUid    来自用户id
     * @param page       分页参数
     * @return
     */
    @Select({"<script>" +
            "   SELECT * FROM ${tableName} WHERE from_uid = #{fromUid} and is_deleted='0' order by create_time desc" +
            "</script>"})
    public IPage<BusSystemReceivemsgRecord> selectByBusTablePage(@Param("tableName") String tableName,@Param("fromUid")String fromUid, Page<BusSystemReceivemsgRecord> page);


    @Select({"<script>" +
            "   SELECT * FROM ${tableName} WHERE from_uid = #{fromUid} and to_uid=#{toUid} and is_deleted='0' order by create_time desc" +
            "</script>"})
    public IPage<BusSystemReceivemsgRecord> selectByBusTablePage(@Param("tableName") String tableName,@Param("fromUid")String fromUid,@Param("toUid")String toUid,Page<BusSystemReceivemsgRecord> page);

    /**
     * 查询发件记录分页
     * @param tableName  表名
     * @param fromUid    来自用户id
     * @param page       分页参数
     * @return
     */
    @Select({"<script>" +
            "   SELECT * FROM ${tableName} " +
            "   <where>" +
            "       <if test='feild != null and feild != \"\"'>" +
            "           AND feild = #{feild}" +
            "        </if>" +
            "        from_uid = #{fromUid} and is_deleted='0' " +
            "   </where>" +
            "       order by create_time desc" +
            "</script>"})
    public IPage<BusSystemReceivemsgRecord> selectByBusTablePage2(@Param("tableName") String tableName,@Param("fromUid")String fromUid, Page<BusSystemReceivemsgRecord> page);

}




